package com.mym.test;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/12 14:04
 * @description
 */
// 宠物父类
// 宠物父类
abstract class Pet1 {
    private String nickname;
    private int health;
    private int intimacy;

    public Pet1(String nickname, int health, int intimacy) {
        this.nickname = nickname;
        this.health = health;
        this.intimacy = intimacy;
    }

    public abstract void eat();

    // 公共getter/setter方法
    public int getHealth() { return health; }
    public void setHealth(int health) { this.health = health; }
    public String getNickname() { return nickname; }
}

// 狗狗类
class Dog1 extends Pet1 {
    private String breed;

    public Dog1(String nickname, int health, int intimacy, String breed) {
        super(nickname, health, intimacy);
        this.breed = breed;
    }

    @Override
    public void eat() {
        setHealth(getHealth() + 3);  // 健康值+3
        System.out.println(getNickname() + "吃狗粮，健康值+3");
    }
}

// 企鹅类
class Penguin extends Pet1 {
    private String gender;

    public Penguin(String nickname, int health, int intimacy, String gender) {
        super(nickname, health, intimacy);
        this.gender = gender;
    }

    @Override
    public void eat() {
        setHealth(getHealth() + 5);  // 健康值+5
        System.out.println(getNickname() + "吃鱼，健康值+5");
    }
}

// 主人类
class Owner1 {
    // 多态实现喂食方法
    public void feed(Pet1 pet) {
        System.out.println("主人开始喂食" + pet.getNickname());
        pet.eat();
    }
}


